<?php
class LocationLoggedIn extends Zend_Form {
	
	private $user;
	
	public function LocationLoggedIn($user) {
		$this->user = $user;
		$this->__construct();
	}
	
	public function init() {
		$this->setMethod("POST");
		$this->setName("locationLoggedIn");
		
		$element = new Zend_Form_Element_Hidden("id");
        $element->setValue($this->user->id);
        $this->addElement($element);
        
        $countryId= City::getCountry($this->user->location)->id;
        $cityId = City::getTopCity($this->user->location)->id;
        if ($this->user->location != $cityId)
       		$regionId = $this->user->location;  
        
        $element = new Zend_Form_Element_Select("country");
        $element->setLabel("Country:");
        $element->addMultiOption(0, "-- Select country --");
        $element->addMultiOptions(Country::getAllCountryAsArray());
        $element->setValue($countryId);
        $this->addElement($element);
        
        $element = new Zend_Form_Element_Select("city");
        $element->setLabel("City:");
        $element->addMultiOption(0, "-- Select city --");
        $element->addMultiOptions(Country::getTopCityByCountryAsArray($countryId));
        $element->setValue($cityId);
        $element->setRegisterInArrayValidator(false);
        $this->addElement($element);
        
        $element = new Zend_Form_Element_Select("region");
        $element->setLabel("Region:");
        $element->addMultiOptions(array("0"=>"-- Select region --"));
        $element->addMultiOptions(City::getSubCityAsArray($cityId));
        $element->setValue($regionId);
        $element->setRegisterInArrayValidator(false);
        $this->addElement($element);
        
        
        $element = new Zend_Form_Element_Submit("save");
        $this->addElement($element);
	}
}
?>